namespace SinaFinance.ChartLibrary.AxisLibrary
{
    using SinaFinanceBaseClassLibrary;
    using System;
    using System.Collections;
    using System.Collections.Generic;
    using System.Diagnostics;
    using System.Windows;
    using System.Windows.Controls;
    using System.Windows.Media;
    using System.Windows.Media.Animation;

    public partial class  VolumnAxis : UserControl
    {
        //private bool _contentLoaded;
        private double bottomSpan = 0.0;
        private SinaFinanceBaseClassLibrary.ColumnTypeEnum columnTypeEnum = SinaFinanceBaseClassLibrary.ColumnTypeEnum.TimeSharing;
        private Canvas coverCanvas = new Canvas();
        private int def_COULUMNSCOUNT = 240;
        private int def_XAXISMARKCOUNT = 8;
        private int def_YAXISMARKCOUNT = 4;
        private bool isOnload = true;
        private int keyFramesAmount = 20;
        //internal Grid LayoutRoot;
        private double leftSpan = 0.0;
        private double rightSpan = 0.0;
        //internal Canvas rootCanvas;
        private List<TimeSharingPoint> timeSharingPoints = new List<TimeSharingPoint>();
        private double topSpan = 0.0;
        private List<bool> volumnFlagList = new List<bool>();
        private List<string> yAxisDatalist = new List<string>();

        public VolumnAxis()
        {
            this.InitializeComponent();
            base.Loaded += new RoutedEventHandler(this.VolumnAxis_Loaded);
        }

        public void BeginTimeSharingLineStoryboard()
        {
        }

        //[DebuggerNonUserCode]
        //public void InitializeComponent()
        //{
        //    if (!this._contentLoaded)
        //    {
        //        this._contentLoaded = true;
        //        Application.LoadComponent(this, new Uri("/SinaFinance;component/ChartLibrary/AxisLibrary/VolumnAxis.xaml", UriKind.Relative));
        //        this.LayoutRoot = (Grid) base.FindName("LayoutRoot");
        //        this.rootCanvas = (Canvas) base.FindName("rootCanvas");
        //    }
        //}

        private List<double> InitVolumnList()
        {
            TimeSharingPoint point;
            for (int i = this.TimeSharingPoints.Count - 1; i > -1; i--)
            {
                point = this.TimeSharingPoints[i];
                if (((point.XInfo.Equals("09:29:00") || point.XInfo.Equals("09:30:00")) || point.XInfo.Equals("12:59:00")) || point.XInfo.Equals("13:00:00"))
                {
                    this.TimeSharingPoints.RemoveAt(i);
                }
            }
            List<double> list = new List<double>();
            IEnumerator enumerator = (IEnumerator) this.timeSharingPoints.GetEnumerator();
            while (enumerator.MoveNext())
            {
                point = (TimeSharingPoint) enumerator.Current;
                double num2 = Convert.ToDouble(point.VolumnInfo.ToString());
                list.Add(num2);
            }
            return list;
        }

        public static object ReferenceTypeConvertToObject(object color)
        {
            object obj2 = new object();
            return color;
        }

        private void storyboard_CanvasTranslateTransform_Completed(object sender, EventArgs e)
        {
        }

        private void storyboard_CanvasWidth_Completed(object sender, EventArgs e)
        {
        }

        private void VolumnAxis_Loaded(object sender, RoutedEventArgs e)
        {
            Storyboard storyboard = new Storyboard();
            Storyboard storyboard2 = new Storyboard();
            DoubleAnimationUsingKeyFrames frames = new DoubleAnimationUsingKeyFrames();
            DoubleAnimationUsingKeyFrames frames2 = new DoubleAnimationUsingKeyFrames();
            List<SplineDoubleKeyFrame> list = new List<SplineDoubleKeyFrame>();
            List<SplineDoubleKeyFrame> list2 = new List<SplineDoubleKeyFrame>();
            if (base.Width <= 0.0)
            {
                base.Width = 600.0;
            }
            if (base.Height <= 0.0)
            {
                base.Height = 400.0;
            }
            List<double> list3 = this.InitVolumnList();
            AxisSysVolumn volumn = new AxisSysVolumn {
                ColumnTypeEnum = this.columnTypeEnum,
                Width = base.Width,
                Height = base.Height,
                LeftSpan = this.leftSpan,
                RightSpan = this.rightSpan,
                TopSpan = this.topSpan,
                ParentCanvas = this.rootCanvas,
                BottomSpan = this.bottomSpan,
                VolumnInfoList = list3,
                VolumnFlagList = this.volumnFlagList,
                YaxisDatalist = this.yAxisDatalist,
                Def_XAXISMARKCOUNT = this.def_XAXISMARKCOUNT,
                Def_YAXISMARKCOUNT = this.def_YAXISMARKCOUNT,
                Def_COULUMNSCOUNT = this.def_COULUMNSCOUNT
            };
            volumn.RenderAxisSys();
            this.rootCanvas.Width = base.Width;
            this.rootCanvas.Height = base.Height;
            LinearGradientBrush brush = new LinearGradientBrush();
            GradientStop stop = new GradientStop();
            GradientStop stop2 = new GradientStop();
            stop.Color = Color.FromArgb(0xff, 0x13, 0x1b, 0x29);
            stop.Offset = 0.0;
            stop2.Color = Color.FromArgb(0xff, 0x1c, 0x2e, 0x41);
            stop2.Offset = 1.0;
            brush.StartPoint = new Point(0.0, 0.0);
            brush.EndPoint = new Point(0.0, 1.0);
            brush.GradientStops.Add(stop);
            brush.GradientStops.Add(stop2);
            this.rootCanvas.Background = brush;
            TransformGroup group = new TransformGroup();
            ScaleTransform transform = new ScaleTransform();
            SkewTransform transform2 = new SkewTransform();
            RotateTransform transform3 = new RotateTransform();
            TranslateTransform transform4 = new TranslateTransform();
            group.Children.Add(transform);
            group.Children.Add(transform2);
            group.Children.Add(transform3);
            group.Children.Add(transform4);
            this.coverCanvas.RenderTransform = group;
            if (this.isOnload)
            {
                int num;
                SplineDoubleKeyFrame frame;
                this.coverCanvas.Width = volumn.pointRightTop.X - volumn.pointLeftTop.X;
                this.coverCanvas.Height = volumn.pointRightBottom.Y - volumn.pointRightTop.Y;
                this.coverCanvas.Margin = new Thickness(volumn.pointLeftTop.X + 1.0, volumn.pointLeftTop.Y, 0.0, 0.0);
                this.coverCanvas.SetValue(Canvas.ZIndexProperty, 15);
                this.coverCanvas.SetValue(FrameworkElement.NameProperty, ReferenceTypeConvertToObject("timeSharingCoverCanvas"));
                this.coverCanvas.Background = brush;
                if (!this.rootCanvas.Children.Contains(this.coverCanvas))
                {
                    this.rootCanvas.Children.Add(this.coverCanvas);
                }
                base.Resources.Remove("WidthStoryboard");
                base.Resources.Remove("TranslateTransformStoryboard");
                base.Resources.Add("WidthStoryboard", storyboard);
                base.Resources.Add("TranslateTransformStoryboard", storyboard2);
                storyboard.Stop();
                storyboard2.Stop();
                frames.SetValue(Storyboard.TargetPropertyProperty, new PropertyPath("(FrameworkElement.Width)", new object[0]));
                frames.SetValue(Storyboard.TargetNameProperty, ReferenceTypeConvertToObject("timeSharingCoverCanvas"));
                frames2.SetValue(Storyboard.TargetPropertyProperty, new PropertyPath("(UIElement.RenderTransform).(TransformGroup.Children)[3].(TranslateTransform.X)", new object[0]));
                frames2.SetValue(Storyboard.TargetNameProperty, ReferenceTypeConvertToObject("timeSharingCoverCanvas"));
                for (num = 0; num < this.keyFramesAmount; num++)
                {
                    frame = new SplineDoubleKeyFrame();
                    frames.KeyFrames.Add(frame);
                    list.Add(frame);
                }
                for (num = 0; num < this.keyFramesAmount; num++)
                {
                    frame = new SplineDoubleKeyFrame();
                    frames2.KeyFrames.Add(frame);
                    list2.Add(frame);
                }
                storyboard.Children.Add(frames);
                storyboard2.Children.Add(frames2);
                double num2 = this.coverCanvas.Width / ((double) this.keyFramesAmount);
                for (num = 0; num < this.keyFramesAmount; num++)
                {
                    list[num].KeyTime = KeyTime.FromTimeSpan(TimeSpan.FromSeconds((double) (num * 0.2)));
                    list[num].Value = this.coverCanvas.Width - (num2 * (num + 1));
                    list2[num].KeyTime = KeyTime.FromTimeSpan(TimeSpan.FromSeconds((double) (num * 0.2)));
                    list2[num].Value = num2 * (num + 1);
                }
                storyboard.Begin();
                storyboard2.Begin();
                storyboard.Completed += new System.EventHandler(this.storyboard_CanvasWidth_Completed);
                storyboard2.Completed += new System.EventHandler(this.storyboard_CanvasTranslateTransform_Completed);
            }
        }

        public double BottomSpan
        {
            get
            {
                return this.bottomSpan;
            }
            set
            {
                this.bottomSpan = value;
            }
        }

        public SinaFinanceBaseClassLibrary.ColumnTypeEnum ColumnTypeEnum
        {
            get
            {
                return this.columnTypeEnum;
            }
            set
            {
                this.columnTypeEnum = value;
            }
        }

        public int Def_COULUMNSCOUNT
        {
            get
            {
                return this.def_COULUMNSCOUNT;
            }
            set
            {
                this.def_COULUMNSCOUNT = value;
            }
        }

        public int Def_XAXISMARKCOUNT
        {
            get
            {
                return this.def_XAXISMARKCOUNT;
            }
            set
            {
                this.def_XAXISMARKCOUNT = value;
            }
        }

        public int Def_YAXISMARKCOUNT
        {
            get
            {
                return this.def_YAXISMARKCOUNT;
            }
            set
            {
                this.def_YAXISMARKCOUNT = value;
            }
        }

        public bool IsOnload
        {
            get
            {
                return this.isOnload;
            }
            set
            {
                this.isOnload = value;
            }
        }

        public double LeftSpan
        {
            get
            {
                return this.leftSpan;
            }
            set
            {
                this.leftSpan = value;
            }
        }

        public double RightSpan
        {
            get
            {
                return this.rightSpan;
            }
            set
            {
                this.rightSpan = value;
            }
        }

        public List<TimeSharingPoint> TimeSharingPoints
        {
            get
            {
                return this.timeSharingPoints;
            }
            set
            {
                this.timeSharingPoints = value;
            }
        }

        public double TopSpan
        {
            get
            {
                return this.topSpan;
            }
            set
            {
                this.topSpan = value;
            }
        }

        public List<bool> VolumnFlagList
        {
            get
            {
                return this.volumnFlagList;
            }
            set
            {
                this.volumnFlagList = value;
            }
        }

        public List<string> YaxisDatalist
        {
            get
            {
                return this.yAxisDatalist;
            }
            set
            {
                this.yAxisDatalist = value;
            }
        }
    }
}
